﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using System.Timers;
using System.Diagnostics;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using BaseAttack;

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace TestUnitClass
{
    [TestClass]
    public class TestUnit
    {

        public TestUnit()
        {
            //TO DO stuff
        }
        [TestMethod]
        public void TestHitTestFalse()
        {
            Unit TestingUnit = new BaseAttack.Unit(new Canvas(), new Point(10, 10));
            Assert.IsFalse(TestingUnit.HitTest(new Point(35, 35)));
        }

        [TestMethod]
        public void TestHitTestTrue()
        {
            Unit TestingUnit = new BaseAttack.Unit(new Canvas(), new Point(15, 15));
            Assert.IsTrue(TestingUnit.HitTest(new Point(17, 18)));
        }

        [TestMethod]
        public void TestAddMarker()
        {
            Unit TestingUnit = new BaseAttack.Unit(new Canvas(), new Point(150, 150));
            TestingUnit.AddMarker(new Point(240, 204));
            Assert.AreEqual(150.0, TestingUnit.GetVisiblePath().ElementAt(0).X1);
            Assert.AreEqual(150.0, TestingUnit.GetVisiblePath().ElementAt(0).Y1);
            Assert.AreEqual(240.0, TestingUnit.GetVisiblePath().ElementAt(0).X2);
            Assert.AreEqual(204.0, TestingUnit.GetVisiblePath().ElementAt(0).Y2);
        }

        [TestMethod]
        public void TestCommitMarkers()
        {
            //Creating the initial setup required for commit markers function.
            Unit TestingUnit = new BaseAttack.Unit(new Canvas(), new Point(200, 600));
            TestingUnit.AddMarker(new Point(210, 600));
            TestingUnit.AddMarker(new Point(250, 620));

            TestingUnit.CommitMarkers();

            //Creating lines to add to TestVisibleLines list
            Line Line1 = new Line();
            Line1.X1 = 200;
            Line1.Y1 = 600;
            Line1.X2 = 210;
            Line1.Y2 = 600;
            Line1.Stroke = new SolidColorBrush(Color.FromArgb(128, 128, 128, 255));

            Line Line2 = new Line();
            Line2.X1 = 210;
            Line2.Y1 = 600;
            Line2.X2 = 250;
            Line2.Y2 = 620;
            Line2.Stroke = new SolidColorBrush(Color.FromArgb(128, 128, 128, 255));

            //The final output of commitMarkers() will be matched against the TestVisiblePath list.
            List<Line> TestVisiblePath = new List<Line>();
            TestVisiblePath.Add(Line1);
            TestVisiblePath.Add(Line2);

            Assert.AreEqual(TestVisiblePath.Count, TestingUnit.GetVisiblePath().Count);
        }

        [TestMethod]
        public void TestCommitMarkersVisiblePathNullUnitBodyGreen()
        {
            Rectangle TestUnitBody = new Rectangle();
            TestUnitBody.Fill = Brushes.Green;

            Unit TestUnit = new BaseAttack.Unit(new Canvas(), new Point(120, 240));
            TestUnit.CommitMarkers();
            
            Assert.AreEqual(new List<Line>().Count, TestUnit.GetVisiblePath().Count); //visible path list is empty

            Assert.AreEqual(Brushes.Green, TestUnit.GetUnitBody().Fill);

        }

        [TestMethod]
        public void TestResetMarkersWithNullLists()
        {
            List<Line> TestVisiblePathClear = new List<Line>();
            List<Point> TestMarkersList = new List<Point>();

            Unit UnitToTest = new BaseAttack.Unit(new Canvas(), new Point(12, 14));
            UnitToTest.ResetMarkers();

            Assert.AreEqual(new List<Line>().Count, UnitToTest.GetVisiblePath().Count);
            Assert.AreEqual(new List<Point>().Count, UnitToTest.GetMarkersList().Count);
        }

        [TestMethod]
        public void TestResetMarkersWithAddMarkers()
        {
            Unit TestingUnit = new BaseAttack.Unit(new Canvas(), new Point(500, 600));
            TestingUnit.AddMarker(new Point(510, 600));
            TestingUnit.AddMarker(new Point(250, 620));

            //TestingUnit.CommitMarkers();
            TestingUnit.ResetMarkers();

            List<Line> TestVisiblePathClear = new List<Line>();
            List<Point> TestMarkersList = new List<Point>();

            Assert.AreEqual(TestVisiblePathClear.Count, TestingUnit.GetVisiblePath().Count);
            Assert.AreEqual(TestMarkersList.Count, TestingUnit.GetMarkersList().Count);
        }
                
       /* [TestMethod]
        public void TestTicksMoreTicks() // to test the case of: U.Distance(Position, m) < DistanceToMove
        {
            Unit TestingUnit = new BaseAttack.Unit(new Canvas(), new Point(124,234));
            TestingUnit.SetMarker(new Point(140, 230));
         
            List<Target> TestList = new List<Target>();
            Target t = new Target(new Canvas(), new Point(150, 233));
            TestList.Add(t);
            TestList.Add(new Target(new Canvas(), new Point(240, 250)));

            TestingUnit.Tick(200, TestList);
            Assert.AreEqual(140, TestingUnit.getPoint.X);
        }
        
        [TestMethod]
        public void TestTicksLessTicks() // to test the case of: U.Distance(Position, m) > DistanceToMove
        {
            Unit TestingUnit = new BaseAttack.Unit(new Canvas(), new Point(124, 234));
            TestingUnit.SetMarker(new Point(140, 230));

            TestingUnit.Tick(10, null);
            Assert.AreEqual(new List<Line>(), TestingUnit.GetVisiblePath());
        }  */    
    }
}
